<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: gaofang
 * @Date: 2020-11-23 18:29:13
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 19:38:54
-->
<template>
  <a-card :bordered="false" title>
    <!-- 搜索 -->
    <a-form v-bind="layout">
      <a-row>
        <!-- 制单日期 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单日期" ref="sort" prop="sort">
            <a-range-picker
              style="width: 100%"
              v-model="searchForm.sort"
              @change="getRangeTime"
            />
          </a-form-model-item>
        </a-col>
        <!-- 单据号 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="单据号">
            <a-select
              v-model="searchForm.document"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="(item, index) in OrderList"
                :key="index"
                :value="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <!-- <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="存货名称">
            <a-select
              v-model="searchForm.inventoryName"
              style="width: 100%"
              :default-active-first-option="false"
              :show-arrow="false"
              :filter-option="false"
              :not-found-content="null"
              @search="handleSearch"
              @change="getInventoryInfo"
              showSearch
            >
              <a-select-option
                v-for="(item, index) in goodsList"
                :key="index"
                :value="
                  item.inventoryId +
                    '|' +
                    item.inventoryNo +
                    '|' +
                    item.inventoryName +
                    '|' +
                    item.specificationsModel +
                    '|' +
                    item.unit
                "
              >
                {{ item.inventoryName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="存货名称">
            <a-select
              v-model="searchForm.inventoryName"
              @change="changeinventoryId"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in goodsList"
                :key="item.inventoryId"
                :value="item.inventoryNo + '|' + item.inventoryName"
              >
                {{ item.inventoryNo }} {{ item.inventoryName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <!-- 仓库名称 -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="仓库名称">
            <a-select
              v-model="searchForm.depotName"
              @change="changeDepotId"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="item.depotNo + '|' + item.depotName"
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>

      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="审核状态">
            <a-select v-model="searchForm.auditMark" style="width: 100%">
              <a-select-option
                v-for="item in auditMarkList"
                :key="item.value"
                :value="item.value"
                >{{ item.title }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="源单号">
            <a-input v-model="searchForm.sourceNumber"></a-input>
            <!-- <a-select
              v-model="searchForm.sourceNumber"
              style="width: 100%"
            >
              <a-select-option
                v-for="(item, index) in sourceNumberList"
                :key="index"
                :value="item"
                >{{ item }}
              </a-select-option>
            </a-select> -->
          </a-form-model-item>
        </a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单人">
            <a-select
              v-model="searchForm.prepared"
              style="width: 100%"
              showSearch
            >
              <a-select-option
                v-for="(item, index) in PreparedyList"
                :key="index"
                :value="item.id"
              >
                {{ item.id_dictText }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>

      <!-- 所属单位 -->
      <!-- <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="所属单位">
            <a-select
              @change="changestorageUnitId"
              v-model="searchForm.storageUnit"
              showSearch
              style="width: 100%"
            >
              <a-select-option
                v-for="item in storageList"
                :key="item.depotId"
                :value="item.depotNo + '|' + item.depotName"
                >{{ item.depotNo }} {{ item.depotName }}</a-select-option
              >
            </a-select>
          </a-form-model-item>
        </a-col> -->
      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="同步状态">
            <a-select v-model="searchForm.isSynchronized" style="width: 100%">
              <a-select-option
                v-for="item in isSynchronizedList"
                :value="item"
                :key="item"
              >
                {{ item }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <!--  <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="是否入库">
            <a-select v-model="searchForm.whetherInOutMark">
              <a-select-option value="1">是</a-select-option>
              <a-select-option value="0">否</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24">
          <a-form-item label="申请部门">
            <a-tree-select
              v-model="searchForm.deptId"
              style="width: 100%"
              :tree-data="departmentList"
              @change="changeTreeNode"
              allow-clear
              show-search
            >
            </a-tree-select>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <a-form v-bind="layout">
      <a-row style="margin-left: -80px">
        <!-- 存货名称 -->
        <a-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="存货名称">
            <a-select
              v-model="searchForm.inventoryName"
              @change="getInventoryInfo"
              showSearch
              style="width: 100%"
              @search="handleInventoryInfoSearch"
            >
              <a-select-option
                v-for="item in inventoryList"
                :key="item.inventoryId"
                :value="
                  item.inventoryId +
                  '|' +
                  item.inventoryNo +
                  '|' +
                  item.inventoryName +
                  '|' +
                  item.standardModel +
                  '|' +
                  item.unit
                "
              >
                {{ item.inventoryNo }} {{ item.inventoryName }}
                {{ item.standardModel }} {{ item.unit }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <!-- 在建项目 -->
        <a-col :xl="12" :lg="12" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="在建项目"
            ref="cprojectid_dictText"
            prop="cprojectid_dictText"
          >
            <a-select
              v-model="searchForm.cprojectid_dictText"
              @change="cprojectChange"
              style="width: 100%"
              showSearch
            >
              <a-select-option
                v-for="(item, index) in cprojectList"
                :key="index"
                :value="
                  item.jobcode + '|' + item.jobname + '|' + item.pkJobbasfil
                "
              >
                {{ item.jobcode }} {{ item.jobname }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>

      <a-row>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24"></a-col>
        <a-col :xl="8" :lg="8" :md="12" :sm="24" :xs="24"></a-col>

        <a-col
          :xl="8"
          :lg="8"
          :md="12"
          :sm="24"
          :xs="24"
          :style="{ textAlign: 'right' }"
        >
          <a-button type="primary" @click="Search()">查询</a-button>
          <a-button style="margin-left: 8px" @click="Reset()">重置</a-button>
          <a-button style="margin-left: 8px" @click="exportToExcel"
            >导出</a-button
          >
        </a-col>
      </a-row>
    </a-form>
    <!-- 搜索下的表格 -->
    <a-table
      v-cloak
      :columns="columns"
      :data-source="dataSource"
      :pagination="pagination"
      @change="handleTableChange"
      style="margin-top: 20px"
      :scroll="{ x: 1800, y: 670 }"
      size="small"
    >
      <!-- 单据号 -->
      <span slot="document" slot-scope="text, record">
        <a @click="RouterJump(record)">
          {{ text }}
        </a>
      </span>
      <span slot="seeRemarkShelf" slot-scope="text, records">
        <a @click="showRemarkShelf(records)">点击查看</a>
      </span>
      <span slot="shelfNo" slot-scope="text, records">
        <a @click="showShelfNo(records)">点击查看</a>
      </span>
      <!-- <span slot="document" slot-scope="text, record">
        <a v-if="record.auditMark != 1" @click="RouterJump(record)">
          {{ text }}
        </a>
        <span v-if="record.auditMark == 1"> {{ text }} </span>
      </span> -->

      <template slot="options" slot-scope="text, record">
        <a-popconfirm
          ok-text="确定"
          cancel-text="取消"
          @confirm="Delete(record.id)"
          v-if="record.auditMark != 1"
        >
          <template slot="title">
            <p>确定删除？</p>
          </template>
          <a type="danger"> 删除 </a>
        </a-popconfirm>
      </template>
      <!-- <span slot="document" slot-scope="text, record">
        <a @click="RouterJump(record)"> {{ text }} </a>
      </span> -->
      <!-- <span slot="options" slot-scope="text, record">
        <a @click="Delete(record.id)"> 删除 </a>
      </span> -->
    </a-table>
    <a-modal
      title="入库货架"
      :visible="visible1"
      width="40%"
      :labelCol="{ span: 8 }"
      :WapperCol="{ span: 5 }"
      @cancel="handleCancel1"
    >
      {{ this.remarkShelf }}
    </a-modal>
    <a-modal
      title="入库货架"
      :visible="visible2"
      width="40%"
      :labelCol="{ span: 8 }"
      :WapperCol="{ span: 5 }"
      @cancel="handleCancel2"
    >
      {{ this.shelfNo }}
    </a-modal>
  </a-card>
</template>
<script>
// import * as XLSX from "xlsx";

// import { openDownloadDialog, sheet2blob } from "@/utils/export.js";
import { JiJianChuKuHttp } from "@/services/modules/ChuKuGuanLi/JJianChuKu/JiJianChuKu";
const JiJianChuKu = new JiJianChuKuHttp(); // 基建出库
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口
import { mapState, mapGetters } from "vuex"; //

const columns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    align: "center",
    width: "50px",
  },
  {
    title: "单据日期",
    dataIndex: "documentDate",
    key: "documentDate",
    align: "center",
    width: "100px",
  },
  {
    title: "审核标志",
    dataIndex: "auditMark_dictText",
    key: "auditMark_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "同步用友",
    dataIndex: "isSynchronized",
    key: "isSynchronized",
    align: "center",
    width: "80px",
  },
  {
    title: "反审核",
    dataIndex: "isAntiAudit",
    key: "isAntiAudit",
    align: "center",
    width: "80px",
  },
  {
    title: "记账标志",
    dataIndex: "bookkeepingMark_dictText",
    key: "bookkeepingMark_dictText",
    align: "center",
    width: "80px",
  },
  {
    title: "单据号",
    dataIndex: "document",
    key: "document",
    align: "center",
    width: "110px",
    scopedSlots: { customRender: "document" },
  },
  {
    title: "申请部门",
    dataIndex: "deptId_dictText",
    key: "deptId_dictText",
    align: "center",
    width: "120px",
  },
  {
    title: "仓库名称",
    dataIndex: "storname",
    key: "storname",
    align: "center",
    width: "110px",
  },
  // {
  //   title: "所属单位",
  //   dataIndex: "storageUnit_dictText",
  //   key: "storageUnit_dictText",
  //   align: "center",
  // },
  {
    title: "在建项目",
    dataIndex: "cprojectid_dictText",
    key: "cprojectid_dictText",
    align: "center",
    width: "100px",
  },
  {
    title: "存货编码",
    dataIndex: "invcode",
    key: "invcode",
    align: "center",
    width: "100px",
  },

  {
    title: "存货名称",
    dataIndex: "invname",
    key: "invname",
    align: "center",
    width: "100px",
  },
  {
    title: "规格型号",
    dataIndex: "specificationsModel",
    key: "specificationsModel",
    align: "center",
    width: "80px",
  },
  {
    title: "单位",
    dataIndex: "unit",
    key: "unit",
    align: "center",
    width: "80px",
  },
  {
    title: "辅助单位",
    dataIndex: "auxiliaryUnit",
    key: "auxiliaryUnit",
    align: "center",
    width: "80px",
  },
  {
    title: "数量",
    dataIndex: "quantity",
    key: "quantity",
    align: "center",
    width: "80px",
  },
  {
    title: "单价",
    dataIndex: "unitPrice",
    key: "unitPrice",
    align: "center",
    width: "80px",
  },

  {
    title: "金额",
    dataIndex: "originalCurrency",
    key: "originalCurrency",
    align: "center",
    width: "80px",
  },
  {
    title: "批次号",
    dataIndex: "batchNumber",
    key: "batchNumber",
    align: "center",
    width: "100px",
  },
  {
    title: "制单人",
    dataIndex: "singleProducer_dictText",
    key: "singleProducer_dictText",
    align: "center",
    width: "70px",
  },
  {
    title: "负责人",
    dataIndex: "responsiblePerson_dictText",
    key: "responsiblePerson_dictText",
    align: "center",
    width: "70px",
  },
  {
    title: "审核人",
    dataIndex: "inspector_dictText",
    key: "inspector_dictText",
    align: "center",
    width: "70px",
  },

  {
    title: "源单号",
    dataIndex: "sourceNumber",
    key: "sourceNumber",
    align: "center",
    width: "110px",
  },
  // {
  //   //! 这是之前的属性名字,可能后端接口还需要改
  //   title: "在建项目",
  //   dataIndex: "projectsUnderConstruction_dictText",
  //   key: "projectsUnderConstruction_dictText",
  //   align: "center",
  //   width: "110px",
  // },
  // {
  //   title: "货架",
  //   dataIndex: "seeRemarkShelf",
  //   key: "seeRemarkShelf",
  //   align: "center",
  //   width: "80px",
  //   scopedSlots: { customRender: "seeRemarkShelf" },
  // },
  // {
  //   title: "是否入库",
  //   dataIndex: "whetherInOutMark",
  //   key: "whetherInOutMark",
  //   align: "center",
  //   width: "80px",
  // },
  // {
  //   title: "入库货架",
  //   dataIndex: "shelfNo",
  //   key: "shelfNo",
  //   align: "center",
  //   width: "80px",
  //   scopedSlots: { customRender: "shelfNo" },
  // },
  // {
  //   title: "入库时间",
  //   dataIndex: "inoutTime",
  //   key: "inoutTime",
  //   width: "90px",
  //   align: "center",
  //   scopedSlots: { customRender: "inoutTime" },
  // },
  {
    title: "操作",
    dataIndex: "options",
    key: "options",
    align: "center",
    width: "80px",
    scopedSlots: { customRender: "options" },
  },
];

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(
      `selectedRowKeys: ${selectedRowKeys}`,
      "selectedRows: ",
      selectedRows
    );
  },
  onSelect: (record, selected, selectedRows) => {
    console.log(record, selected, selectedRows);
  },
  onSelectAll: (selected, selectedRows, changeRows) => {
    console.log(selected, selectedRows, changeRows);
  },
};

export default {
  data() {
    return {
      departmentList: [], // 部门列表

      isSynchronizedList: ["已同步", "未同步"],

      auditMarkList: [
        {
          value: 1,
          title: "已审核",
        },
        {
          value: 2,
          title: "未审核",
        },
      ],
      // ---------- 分页使用 -------------
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeOptions: ["10", "20", "30"], // 每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
        showSizeChanger: true, // 显示页面条数改变
        showQuickJumper: true, // 显示快速跳转
      },
      queryParam: {
        //查询参数
        page: 1, //第几页
        size: 10, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      },

      // 搜索栏布局
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 },
      },
      layout2: {
        labelCol: { span: 6 },
        wrapperCol: { span: 6 },
      },
      // 搜索列表
      searchForm: {
        // whetherInOutMark:"",//是否出入库
        cprojectid: "",
        document: "", // 单据号
        depotId: "", // 仓库id
        inventoryId: "", // 存货Id
        startTime: "",
        endTime: "",
        storageUnitId: "", // 所属单位Id
        deptId: "", //销售部门id
        applicationDeptId: "", //部门
        prepared: "",
        depotName: undefined, // 仓库名称
        inventoryName: undefined, // 存货名称
        isSynchronized: "", //同步状态

        // storageUnit: undefined, // 所属单位名称

        // dept: undefined, // 销售部门

        sort: null, // 时间段
        auditMark: "", // 单据状态

        sourceNumber: "", // 源单号
      },

      // 销售出库订单列表
      columns,
      dataSource: [],
      rowSelection,

      alreadyCheckTag: false, // 是否审核标志
      alreadyRecordTag: false, // 是否记账标志

      // 列表
      OrderList: [], // 订单列表，返回所有的销售出库单
      storageList: [], // 仓库
      // goodsList: [], // 存货
      inventoryList: [], //存货
      saleDepartmentList: [], // 销售部门
      ALLOrderList: [], // 所有的订单列表,存储订单单号
      sourceNumberList: [], //源单号
      PreparedyList: [], //制单人列表
      cprojectList: [], //在建项目列表
      remarkShelf: "",
      shelfNo: "",
      visible1: false, //修改弹窗
      visible2: false, //修改弹窗

      queryPathCache: "", // 查询缓存
    };
  },
  computed: {
    // 获取本地数据
    ...mapState("user", { currUser: "info", currPost: "position" }),
    ...mapGetters({
      getDepsInfo: "user/getDepsInfo",
    }),
    // ...mapState("setting", ["isMobile"]),
  },
  mounted() {
    this.getDeparmentTree(); //获取部门树=
    this.getOutStorageList(); //
    this.getZaiJianList(); //在建项目列表
    this.getStorageList(); // 仓库列表
    // this.getSaleDepartmentList(); // 获取销售部门
    this.getOrderList(); // 获取订单列表
    this.getPreparedyList(); // 获取制单人列表
  },
  watch: {
    // "$route.query.Id":"getParam"
    $route(to, from) {
      //监听路由是否变化
      console.log("to", to);
      console.log("from", from);
      // window.location.reload();
      this.getOutStorageList();
    },
  },
  methods: {
    // 获取部门列表
    getDeparmentTree() {
      comHttp.getDepartmentList().then((res) => {
        // let tree = this.resetTree(res.result);
        console.log("获取部门树::::", res.result);
        this.departmentList = res.result;
        console.log(this.departmentList, "11111111");
        // this.resetTree(this.departmentList);
        this.changeCorpData(this.departmentList);
      });
    },
    // 改变用友传递过来的数据为组件能识别的数据
    changeCorpData(Tree) {
      Tree.forEach((element) => {
        element["title"] = element.deptname;
        element["children"] = element.syncDepartmentFilesEntityList;
        element["key"] = element.pkDeptdoc;
        element["value"] = element.deptname;

        if (element.children) {
          this.changeCorpData(element.children);
        }
      });
    },
    // 部门下拉框选择
    changeTreeNode(value, key, c) {
      console.log("key", key);
      console.log("value", value);
      console.log("c", c);
      this.searchForm.applicationDeptId = c.triggerNode.eventKey;
      this.searchForm.deptId = key;
      console.log("选择的值::::", this.searchForm.deptId);
      console.log("applicationDeptId::::", this.searchForm.deptId);
    },
    // 获取制单人列表
    getPreparedyList() {
      comHttp.getPreparedyList().then((res) => {
        var pattern = new RegExp("[\u4E00-\u9FA5]+");

        console.log("获取制单人列表:::::", res);
        let data = res.result.list.filter((item) => {
          if (pattern.test(item.id)) {
            console.log(item.id);
          } else if (item.id == null) {
            console.log(item.id);
          } else {
            return item;
          }
        });
        console.log(data);
        this.PreparedyList = data;
      });
    },
    showRemarkShelf(records) {
      //查看货架按钮
      this.visible1 = !this.visible1;
      console.log(records);
      this.remarkShelf = records.remarkShelf;
    },
    showShelfNo(records) {
      //查看货架按钮
      this.visible2 = !this.visible2;
      console.log(records);
      this.shelfNo = records.shelfNo;
    },
    handleCancel1() {
      // 修查看货架按弹窗取消
      this.visible1 = false;
    },
    handleCancel2() {
      // 修查看货架按弹窗取消
      this.visible2 = false;
    },
    // 仓库物品模糊查询,解决卡顿的问题
    async handleInventoryInfoSearch(value) {
      var goodsList_invname = [];
      var goodsList_invspec = [];
      this.inventoryList = [];

      if (value.match(/^[ ]*$/)) {
        console.log("字符串为空或全空格");
      } else {
        this.inventoryList = [];
        let queryPath = "?name=" + value;
        if (value == "" || value == null) {
          this.inventoryList = [];
        } else {
          await comHttp
            .getSearchInventoryInformationFile(queryPath)
            .then((res) => {
              console.log("res", res.result);
              for (let i = 0; i < res.result.length; i++) {
                let data = {
                  inventoryId: res.result[i].pkInvbasdoc, // 存货 id
                  inventoryName: res.result[i].invname,
                  inventoryNo: res.result[i].invcode,
                  standardModel: res.result[i].invspec,
                  unit: res.result[i].measname,
                };
                goodsList_invname.push(data);
              }
            });
          let queryInventoryBySpec = "?invspec=" + value;
          //规格型号模糊查询
          await comHttp
            .getqueryInventoryBySpec(queryInventoryBySpec)
            .then((res) => {
              console.log("结果规格型号模糊查询", res);

              for (let i = 0; i < res.result.length; i++) {
                let data = {
                  inventoryId: res.result[i].pkInvbasdoc, // 存货 id
                  inventoryNo: res.result[i].invcode, //存货编码
                  inventoryName: res.result[i].invname, //存货名称
                  standardModel: res.result[i].invspec, //规格型号
                  unit: res.result[i].measname, //单位
                };
                goodsList_invspec.push(data);
              }
            });
          //todo 合并去重函数
          await this.mergeArray(goodsList_invname, goodsList_invspec);
        }
      }
    },
    //todo 合并去重函数
    mergeArray(arr1, arr2) {
      let arrs = [...arr1, ...arr2];

      //根据inventoryId去重
      let map = new Map();
      for (let item of arrs) {
        if (!map.has(item.inventoryId)) {
          map.set(item.inventoryId, item);
        }
      }
      this.inventoryList = [...map.values()];
    },
    handleSearch(value) {
      if (value.match(/^[ ]*$/)) {
        console.log("字符串为空或全空格");
      } else {
        this.goodsList = [];
        console.log("value", value);
        let query = "?name=" + value;
        console.log("query", query);
        if (value == "" || value == null) {
          this.goodsList = [];
        } else {
          comHttp.getgetSearchInventoryInformationFile(query).then((res) => {
            console.log("结果为", res);
            // this.goodsList = res.result;
            for (let i = 0; i < res.result.length; i++) {
              if (
                res.result[i].specificationsModel == "null" ||
                res.result[i].specificationsModel == null
              ) {
                res.result[i].specificationsModel = "";
              }
              if (res.result[i].unit == "null" || res.result[i].unit == null) {
                res.result[i].unit = "";
              }
              let data = {
                inventoryId: res.result[i].id, // 存货 id
                inventoryNo: res.result[i].inventoryNo, //存货编码
                inventoryName: res.result[i].inventoryName, //存货名称
                specificationsModel: res.result[i].specificationsModel, //规格型号
                unit: res.result[i].unit, //单位
              };
              this.goodsList.push(data);
            }
          });
        }
      }
    },
    //获取在建项目列表
    getZaiJianList() {
      JiJianChuKu.getZaiJian().then((res) => {
        console.log("在建项目", res);
        this.cprojectList = res.result;
      });
    },
    // 获取存货信息
    getInventoryInfo(value, option) {
      this.searchForm.inventoryId = option.key;
      console.log("存货id::::", this.searchForm.inventoryId);
    },
    // getInventoryInfo() {
    //   console.log("searchForm", this.searchForm);
    //   let array = this.searchForm.inventoryName.split("|");
    //   console.log("array", array);
    //   this.searchForm.inventoryName = array[2];
    //   this.searchForm.inventoryId = array[0];
    // },
    // 获取基建出库列表  默认查询路径为第一页,
    getOutStorageList() {
      let _query = this.queryPathCache;

      if (!_query) {
        _query =
          "?pageNo=" +
          this.queryParam.page +
          "&pageSize=" +
          this.queryParam.size +
          "&inOutCategoryIdentification=5" +
          "&inOutIdentification=2";
      }
      comHttp.getInOrOutStorageOrderAndGoodsList(_query).then((res) => {
        this.dataSource = [];
        this.ALLOrderList = [];
        console.log("获取仓库列表", res);

        const pagination = { ...this.pagination };
        pagination.total = res.result.total;
        pagination.pageSize = res.result.size;
        pagination.current = res.result.current;
        this.pagination = pagination;

        //  this.dataSource=res.result.records;

        for (let i = 0; i < res.result.records.length; i++) {
          // console.log("11111111111111111111111");
          // let data=res.result.records[i];
          // delete data.document;

          let data = {
            document: res.result.records[i].document, //单据号
            id: res.result.records[i].id,
            key: (res.result.current - 1) * 10 + i + 1,
            documentDate: res.result.records[i].documentDate, // 单据日期
            auditMark_dictText: res.result.records[i].auditMark_dictText, // 审核标志
            auditMark: res.result.records[i].auditMark, // 审核标志

            isSynchronized: res.result.records[i].isSynchronized, // 同步用友
            isAntiAudit: res.result.records[i].isAntiAudit, // 反审核

            bookkeepingMark: res.result.records[i].bookkeepingMark, // 记账标志
            bookkeepingMark_dictText:
              res.result.records[i].bookkeepingMark_dictText, // 记账标志
            cprojectid: res.result.records[i].cprojectid, //在建项目
            cprojectid_dictText: res.result.records[i].cprojectid_dictText, //在建项目
            storname: res.result.records[i].storname, // 仓库名称
            deptId_dictText: res.result.records[i].deptId_dictText, // 申请部门名称
            // 客户
            // 业务员
            // storageUnit_dictText: res.result.records[i].storageUnit_dictText, // 所属单位
            invcode: res.result.records[i].invcode, // 存货编码
            invname: res.result.records[i].invname, // 存货名称
            specificationsModel: res.result.records[i].invspec, // 规格型号
            unit: res.result.records[i].measname, // 单位
            auxiliaryUnit: res.result.records[i].auxiliaryUnit_dictText, // 辅助单位
            quantity: res.result.records[i].quantity, // 数量
            // unitPrice: res.result.records[i].unitPrice, // 单价
            // originalCurrency: res.result.records[i].originalCurrency,// 金额
            // 批次号
            // giveaway_dictText: res.result.records[i].giveaway_dictText, // 是否赠品
            batchNumber: res.result.records[i].batchNumber, // 批次号

            singleProducer_dictText:
              res.result.records[i].singleProducer_dictText, // 制单人
            singleProducer: res.result.records[i].singleProducer, // 制单人

            responsiblePerson_dictText:
              res.result.records[i].responsiblePerson_dictText, // 负责人
            inspector_dictText: res.result.records[i].inspector_dictText, // 审核人
            inspector: res.result.records[i].inspector, // 审核人Id
            // 记账标志
            sourceNumber: res.result.records[i].sourceNumber, // 源单号

            sendReceiveType: res.result.records[i].sendReceiveType, // 收发类别
            sendReceiveType_dictText:
              res.result.records[i].sendReceiveType_dictText, // 收发类别

            projectsUnderConstruction_dictText:
              res.result.records[i].projectsUnderConstruction_dictText, // 在建项目
            // remark: res.result.records[i].remark, // 备注

            remarkShelf: res.result.records[i].remarkShelf, //货架
            shelfNo: res.result.records[i].shelfNo, //实际出入库货架d,
            inoutTime: res.result.records[i].inoutTime, //实际出入库时间
            // whetherInOutMark:
            //   res.result.records[i].whetherInOutMark == 0 ? "否" : "是", //实际是否出入库标志
          };
          this.dataSource.push(data);
          // 如果所有订单列表中包含了该订单
          // if (this.ALLOrderList.indexOf(res.result.records[i].document) > -1) {
          //   console.log("没有重复");
          //   this.dataSource.push(data);
          // } else {
          //   console.log("已经重复");
          //   this.ALLOrderList.push(res.result.records[i].document);
          //   data[`document`] = res.result.records[i].document;
          //   this.dataSource.push(data);
          // }
        }
      });
    },
    // 获取全局查询条件
    getQueryPath() {
      console.log(this.searchForm);
      let queryPath =
        "?pageNo=" +
        this.queryParam.page +
        "&pageSize=" +
        this.queryParam.size +
        "&inOutCategoryIdentification=5" +
        "&inOutIdentification=2" +
        "&document=" +
        this.searchForm.document + // 单据号
        "&depotId=" +
        this.searchForm.depotId + // 仓库名称
        "&inventoryId=" +
        this.searchForm.inventoryId + // 存货名称
        "&beginDate=" +
        this.searchForm.startTime + //
        "&endDate=" +
        this.searchForm.endTime + //
        "&auditMark=" +
        this.searchForm.auditMark + //单据状态,即审核标志
        "&sourceNumber=" +
        this.searchForm.sourceNumber + //源单号
        "&singleProducer=" +
        this.searchForm.prepared +
        "&cprojectid=" +
        this.searchForm.cprojectid +
        "&isSynchronized=" +
        this.searchForm.isSynchronized +
        // "&whetherInOutMark=" + //是否入库
        // this.searchForm.whetherInOutMark +
        "&deptId=" + //部门
        this.searchForm.applicationDeptId;

      this.queryPathCache = queryPath;

      return queryPath; // 返回的查询条件
    },

    // 重置当前页码及页码参数
    resetPagination() {
      this.pagination = {
        total: 0,
        current: 1,
        pageSize: 10, //每页中显示10条数据
        pageSizeOptions: ["10", "20", "30"], // 每页中显示的数据
        showTotal: (total) => `共有${total}条数据`, //分页中显示总的数据
        showSizeChanger: true, // 显示页面条数改变
        showQuickJumper: true, // 显示快速跳转
      };
      //查询参数
      this.queryParam = {
        page: 1, //第几页
        size: 10, //每页中显示数据的条数
        hosName: "",
        hosCode: "",
        province: "",
        city: "",
      };
    },
    //在建项目触发函数
    cprojectChange(value) {
      console.log("在建项目触发函数value", value);
      let array = value.split("|");
      this.searchForm.projectsUnderConstruction = array[2];
      this.searchForm.cprojectid = array[2];
      this.searchForm.cprojectid_dictText = array[1];
      console.log("在建项目触发函数this.Form", this.Form);
    },
    // 分页函数
    handleTableChange(pagination) {
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.queryParam.page = pagination.current;
      this.queryParam.size = pagination.pageSize;
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
    },

    // 查询
    Search() {
      let queryPath = this.getQueryPath();
      this.getOutStorageList(queryPath);
      console.log("查询条件为:::", queryPath);
    },

    // -------------- 完成 ---------------------
    // 路由跳转函数
    RouterJump(record) {
      if (record.isAntiAudit === "已反审核") {
        //审核人跳修改
        if (record.inspector == this.$store.state.user.info.id) {
          // 制单人 == 当前登录人 && 审核人 ！= 当前登录人
          // 去修改吧！！！
          this.$router.push({
            path: "InfrastructureOutput",
            query: {
              Id: record.id,
              document: record.document,
              auditMark: record.auditMark,
              singleProducer: record.singleProducer,
              isAntiAudit: record.isAntiAudit,
            },
          });
          return;
        }
      }
      if (record.auditMark == 1) {
        // 已经审核
        this.alreadyCheckTag = false; // 不可审核
      } else if (record.auditMark == 2) {
        // 未审核
        this.alreadyCheckTag = true; // 可以审核
      }

      if (record.bookkeepingMark == 1) {
        // 已经记账
        this.alreadyRecordTag = false; // 不可记账
      } else if (record.bookkeepingMark == 2) {
        // 未记账
        this.alreadyRecordTag = true; // 可以记账
      }

      console.log(":::::::routerjump.record::::", record);

      // 审核人
      if (record.inspector == this.$store.state.user.info.id) {
        console.log("这是审核人,能审核,能提交");
        this.$router.push({
          path: "InfrastructureOutputDetail",
          query: {
            Id: record.id,
          },
        });
      }
      // 制单人
      else if (record.singleProducer == this.$store.state.user.info.id) {
        console.log("这是制单人,能修改");
        // 如果未审核，则能修改，审核过了则不能修改
        if (record.auditMark == 2) {
          this.$router.push({
            path: "InfrastructureOutput", //基建出库
            query: {
              Id: record.id,
            },
          });
        } else {
          // 审核过了,不能修改
          this.$router.push({
            path: "InfrastructureOutputDetail", //基建出库详情
            query: {
              Id: record.id,
            },
          });
        }
      }

      // 其余人员
      else {
        console.log("这是其余人员,仅能查看，不能审核和提交");
        this.$router.push({
          path: "InfrastructureOutputDetail",
          query: {
            Id: record.id,
          },
        });
      }
    },
    // 获取仓库列表
    getStorageList() {
      // 获取仓库名称
      this.storageList = [];
      comHttp.getStorageName().then((res) => {
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            depotName: res.result[i].storname, //仓库名称
            depotNo: res.result[i].storcode, //仓库编码
            depotId: res.result[i].pkStordoc, //id
          };
          this.storageList.push(data);
        }
      });
    },
    // getStorageList() {
    //   this.storageList = [];
    //   // 获取仓库名称
    //   comHttp.getStorageName().then((res) => {
    //     console.log("获取所有仓库", res);
    //     for (let i = 0; i < res.result.records.length; i++) {
    //       let data = {
    //         id: res.result.records[i].pkStordoc,//id
    //         depotName: res.result.records[i].storname,
    //         depotNo: res.result.records[i].storcode,//仓库编码
    //       };
    //       this.storageList.push(data);
    //     }
    //   });
    // },
    // 获取仓库编码
    changeDepotId(value, option) {
      this.searchForm.depotId = option.key;
      // this.getGoodSInfo(option.key);
      console.log("仓库id::::", this.searchForm.depotId);
    },

    // 获取存货id
    changeinventoryId(value, option) {
      this.searchForm.inventoryId = option.key;
      console.log("存货id::::", this.searchForm.inventoryId);
    },
    // 获取所属单位id
    changestorageUnitId(value, option) {
      this.searchForm.storageUnitId = option.key;
      console.log("所属单位id::::", this.searchForm.storageUnitId);
    },

    //获取部门id
    changedeptId(value, option) {
      this.searchForm.deptId = option.key;
      console.log("部门id::::", this.searchForm.deptId);
    },
    // 获取时间段
    getRangeTime(date, dateString) {
      this.searchForm.startTime = dateString[0];
      this.searchForm.endTime = dateString[1];
    },
    // 重置查询条件
    Reset() {
      this.searchForm = {
        document: "", // 单据号
        depotId: "", // 仓库id
        inventoryId: "", // 存货Id
        startTime: "",
        endTime: "",
        storageUnitId: "", // 所属单位Id
        deptId: "", //销售部门id
        prepared: "",
        depotName: undefined, // 仓库名称
        inventoryName: undefined, // 存货名称
        isSynchronized: "", //同步状态

        // storageUnit: undefined, // 所属单位名称

        // dept: undefined, // 销售部门

        sort: null, // 时间段
        auditMark: "", // 单据状态
        sourceNumber: "", // 源单号

        // document: "", // 单据号
        // documentId: "", // 单据号id
        // depotId: "", // 仓库id
        // depotName: undefined, // 仓库名称
        // inventoryName: undefined, // 存货名称
        // inventoryId: "", // 存货Id
        // // storageUnit: undefined, // 所属单位名称
        // storageUnitId: "", // 所属单位Id
        // dept: undefined, // 销售部门
        // deptId: "", //销售部门id

        // sort: null, // 时间段
        // startTime: "",
        // endTime: "",
      };

      this.queryPathCache = "";

      this.resetPagination();
      this.getOutStorageList();
    },

    // 删除
    Delete(id) {
      comHttp.deleteInOrOutStorageOrderAndGoods("?id=" + id).then((res) => {
        if (res && res.code === 200) {
          this.$message.success("删除成功");
          this.getOutStorageList();
        } else {
          this.$message.error("删除失败");
        }
      });
    },

    // 根据仓库Id获取物品信息
    // getGoodSInfo(id) {
    //   this.goodsList = [];
    //   comHttp.getInventoryInformationByStorageId("?id=" + id).then((res) => {
    //     console.log("获取存货信息:::::", res);
    //     for (let i = 0; i < res.result.length; i++) {
    //       let data = {
    //         inventoryId: res.result[i].id, // 存货 id
    //         inventoryName: res.result[i].inventoryName,
    //         inventoryNo: res.result[i].inventoryNo,
    //       };
    //       this.goodsList.push(data);
    //     }
    //   });
    // },
    // 获取单据号列表
    getOrderList() {
      let queryPath = "?string=JJCK-";
      comHttp.getOrderList(queryPath).then((res) => {
        console.log("获取基建出库列表:::::", res);
        for (let i = 0; i < res.result.length; i++) {
          this.OrderList.push(res.result[i]);
        }
      });
    },

    // 导出列表
    exportToExcel() {
      this.queryPath =
        "?inOutCategoryIdentification=5" +
        "&inOutIdentification=2" +
        "&document=" +
        this.searchForm.document + // 单据号
        "&depotId=" +
        this.searchForm.depotId + // 仓库名称
        "&inventoryId=" +
        this.searchForm.inventoryId + // 存货名称
        "&beginDate=" +
        this.searchForm.startTime + //
        "&endDate=" +
        this.searchForm.endTime + //
        "&auditMark=" +
        this.searchForm.auditMark + //单据状态,即审核标志
        "&sourceNumber=" +
        this.searchForm.sourceNumber + //源单号
        "&singleProducer=" +
        this.searchForm.prepared +
        "&cprojectid=" +
        this.searchForm.cprojectid +
        "&isSynchronized=" +
        this.searchForm.isSynchronized +
        // "&whetherInOutMark=" + //是否入库
        // this.searchForm.whetherInOutMark +
        "&deptId=" + //部门
        this.searchForm.applicationDeptId;
      comHttp.exportInfrastructureOut(this.queryPath).then((response) => {
        //如果后端返回的result是进过Blob处理的，直接 window.URL.createObjectURL(result)，如果没有，就需要先实例化new Blod处理之后再window.URL.createObjectURL(blob)。
        //文件名 文件保存对话框中的默认显示
        let fileName = "基建出库单.xls";
        let data = response.data;
        if (!data) {
          return;
        }
        console.log(response);
        //构造a标签 通过a标签来下载
        let url = window.URL.createObjectURL(new Blob([data]));
        let a = document.createElement("a");
        a.style.display = "none";
        a.href = url;
        //此处的download是a标签的内容，固定写法，不是后台api接口
        a.setAttribute("download", fileName);
        document.body.appendChild(a);
        //点击下载
        a.click();
        // 下载完成移除元素
        document.body.removeChild(a);
        // 释放掉blob对象
        window.URL.revokeObjectURL(url);
      });
    },
  },
};
</script>
<style scoped lang="less">
.avatar-uploader > .ant-upload {
  width: 160px;
  height: 160px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
textarea {
  border: 0;
  border-radius: 5px;
  border: 1px #d9d9d9 solid;
  width: 100%;
  height: 100px;
  padding: 10px;
  resize: none;
}
#feng_kong_cuo_shi_1 {
  width: 700px;
}
</style>
